@echo off
chcp 65001 >nul
echo ========================================
echo 安装 Android SDK 平台
echo ========================================
echo.

REM 检查 SDK 路径
set "SDK_PATHS=C:\Users\%USERNAME%\AppData\Local\Android\Sdk;C:\Android\Sdk;C:\Program Files\Android\Sdk"

for %%p in (%SDK_PATHS%) do (
    if exist "%%p\cmdline-tools\latest\bin\sdkmanager.bat" (
        echo 找到 SDK 管理器: %%p
        set "ANDROID_SDK_ROOT=%%p"
        goto :install_platforms
    )
)

echo 未找到 Android SDK 管理器！
echo 请确保已安装 Android SDK Command-line Tools
echo.
pause
exit /b 1

:install_platforms
echo 使用 SDK 路径: %ANDROID_SDK_ROOT%
echo.

echo 正在安装 Android SDK 平台...

REM 安装项目需要的平台
echo 安装 Android API 30 (Android 11)...
"%ANDROID_SDK_ROOT%\cmdline-tools\latest\bin\sdkmanager.bat" "platforms;android-30"

echo 安装 Android API 31 (Android 12)...
"%ANDROID_SDK_ROOT%\cmdline-tools\latest\bin\sdkmanager.bat" "platforms;android-31"

echo 安装 Android API 32 (Android 12L)...
"%ANDROID_SDK_ROOT%\cmdline-tools\latest\bin\sdkmanager.bat" "platforms;android-32"

echo 安装 Android API 33 (Android 13)...
"%ANDROID_SDK_ROOT%\cmdline-tools\latest\bin\sdkmanager.bat" "platforms;android-33"

echo 安装 Android API 34 (Android 14)...
"%ANDROID_SDK_ROOT%\cmdline-tools\latest\bin\sdkmanager.bat" "platforms;android-34"

echo.
echo 正在安装对应的 build-tools...

REM 安装对应的 build-tools
echo 安装 build-tools 30.0.3...
"%ANDROID_SDK_ROOT%\cmdline-tools\latest\bin\sdkmanager.bat" "build-tools;30.0.3"

echo 安装 build-tools 31.0.0...
"%ANDROID_SDK_ROOT%\cmdline-tools\latest\bin\sdkmanager.bat" "build-tools;31.0.0"

echo 安装 build-tools 32.0.0...
"%ANDROID_SDK_ROOT%\cmdline-tools\latest\bin\sdkmanager.bat" "build-tools;32.0.0"

echo 安装 build-tools 33.0.0...
"%ANDROID_SDK_ROOT%\cmdline-tools\latest\bin\sdkmanager.bat" "build-tools;33.0.0"

echo 安装 build-tools 34.0.0...
"%ANDROID_SDK_ROOT%\cmdline-tools\latest\bin\sdkmanager.bat" "build-tools;34.0.0"

echo.
echo 正在安装 platform-tools...
"%ANDROID_SDK_ROOT%\cmdline-tools\latest\bin\sdkmanager.bat" "platform-tools"

echo.
echo ========================================
echo Android SDK 平台安装完成！
echo ========================================
echo.
echo 已安装的平台：
echo - Android API 30 (Android 11)
echo - Android API 31 (Android 12)
echo - Android API 32 (Android 12L)
echo - Android API 33 (Android 13)
echo - Android API 34 (Android 14)
echo.
echo 现在可以尝试构建项目了
echo.
pause 